import Vue from 'vue'

// 封装v-title自定义指令
Vue.directive('title', {
  inserted(el, binding) {
    el.style.opacity = 0
    window.onscroll = function() {
      // 需要获取滚动高度
      const stop = document.body.scrollTop || document.documentElement.scrollTop
      if (stop > (binding.value || 30)) {
        el.style.opacity = 1
      } else {
        el.style.opacity = 0
      }
    }
  },
  unbind() {
    window.onscroll = null
  }
})
